// pages/company/index.js
const App = getApp();
const AJAX = require("../../common/request")
const API = require("../../common/api")
const common = require("../../common/common")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navTop: 0,
    navContentHeight: 0,
    placeholderHeight: 0,
    windowHeight: 0,
    scrollHeight: 0,
    headTitleHeight: 0,
    adHeight: 0,
    tabsId: 0,
    tabs: [],
    enterpriseName: "",
    enterpriseLogo: "",
    enterpriseIntroduction: "",
    bEnterpriseScience: [], //科技企业
    UPLOADURL: "",
    REQUESTURL: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    this.setData({
      navTop: App.globalData.navTop,
      navContentHeight: App.globalData.navContentHeight,
      options: JSON.stringify(options),
      UPLOADURL: API.UPLOADURL,
      REQUESTURL: API.REQUESTURL
    })
    const query = wx.createSelectorQuery();
    query.select('.ad').boundingClientRect();
    query.select('#head').boundingClientRect();
    query.select('#tab').boundingClientRect();
    await query.exec((res) => {
      console.log(res)

      this.setData({
        adHeight: res[0].height,
        placeholderHeight: res[1].height,
        scrollHeight: App.globalData.windowHeight - res[0].height - res[2].height - App.globalData.statusBarHeight -22
      })
    });

    await AJAX.POST('/system/AppWechat/getbEnterpriselist', {}).then((res) => {
      if (res.code == 200) {
        this.setData({
          tabs: res.rows[0].childlist,
          enterpriseName: res.rows[0].enterpriseName,
          enterpriseLogo: API.UPLOADURL + res.rows[0].enterpriseLogo,
          enterpriseIntroduction: res.rows[0].enterpriseIntroduction,
        })
        this.data.tabs.forEach((item, index) => {
          item.enterpriseIntroductionContent = item.enterpriseIntroductionContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto"')
          this.setData({
            [`tabs[${index}].enterpriseIntroductionContent`]: common.addDomainToImageUrls(item.enterpriseIntroductionContent, this.data.REQUESTURL)
          })
        })

      }
    })

    AJAX.POST('/system/AppWechat/getbEnterpriseScience', {}).then((res) => {
      if (res.code == 200) {
        this.setData({
          bEnterpriseScience: res.rows,
        })

      }
    })
  },



  setTabs(e) {
    console.log(e)
    this.setData({
      tabsId: e.currentTarget.dataset.index
    })
  },
  goPage() {
    console.log(this.data.tabs[this.data.tabsId].id)
  },
  onShareAppMessage(options) {
    // 默认分享配置
    return {
        title: App.globalData.onShareAppMessage.title,
        path: App.globalData.onShareAppMessage.path,
        imageUrl: App.globalData.onShareAppMessage.imageUrl,
    }
},
})